<template>
  <div class="basePrivilege">
    <div class="btns">
      
      <el-form size="small" inline style="text-align:center">
        <el-form-item label="">
          <el-input
    placeholder="请输入内容"
    
    v-model="param.name">
  </el-input>
        </el-form-item>
        <el-form-item>
           <el-button type="primary" round size="small" icon="el-icon-search" @click="loadbasePrivilege">搜索</el-button>
        </el-form-item>
      </el-form>
       
      <el-button type="primary" size="small" icon="el-icon-edit-outline" @click="toAddHandler">新增</el-button>
      <el-button type="primary" size="small" icon="el-icon-edit-outline" @click="downloadHandler">导出</el-button>

    </div>
    
    <el-table size="small" :data="basePrivileges" border stripe style="width:100%" max-height="500" >
    <el-table-column fixed sortable type="index" index="1" label="序号"></el-table-column>
    <el-table-column fixed sortable label="姓名" prop="name" align="center"></el-table-column>
    <el-table-column fixed sortable label="描述" prop="description" align="center"></el-table-column>
    <el-table-column fixed sortable label="路径" prop="route" align="center"></el-table-column>
    <el-table-column fixed sortable label="路径名字" prop="routeName" align="center"></el-table-column>
    <el-table-column fixed sortable label="类型" prop="type" align="center"></el-table-column>
    <el-table-column fixed sortable label="图标" prop="icon" align="center"></el-table-column>
    <el-table-column fixed sortable label="隐藏" prop="hidden" align="center"></el-table-column>
    <el-table-column fixed sortable label="数字" prop="num" align="center"></el-table-column>
    <el-table-column fixed sortable label="上级id" prop="parentId" align="center"></el-table-column>
    <el-table-column label="操作" align="center">
        <template slot-scope="scope">
           <el-button type="primary" size="mini" icon="el-icon-edit" @click="editHandler(scope.row)" ></el-button > 
          <el-button type="danger" icon="el-icon-delete" size="mini" @click="deleteHandler(scope.row)">
          </el-button>
        
        </template>
    </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {del,get} from "@/utils/request";

export default {
  data() {
    return {
      param:{},
      basePrivileges:[],
    };
  },
  methods: {
    downloadHandler(){
 window.location.href="http://8.131.68.179:9999/base_privilege/download?name"+this.param.name;
    },
    editHandler(row){
      // 跳转到修改页面 （新增页面）
      // 携带当前行的数据
      this.$router.push({
        path:"/basePrivilege/create",    //跳转的路由（前端）
        query:row   // 携带参数
      })
    },
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://8.131.68.179:9999/base_privilege/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadbasePrivilege();
        });
      });
    },
    toAddHandler() {
      this.$router.push("/basePrivilege/create")
    },
    loadbasePrivilege() {
      let url = "http://8.131.68.179:9999//base_privilege/query"
      get(url, this.param).then((resp) => {
        this.basePrivileges = resp.data;
      });
    },
  },
     created() {
    this.loadbasePrivilege();
  },
  };
</script>
<style scoped>
.btns {
  margin-bottom: 0.5em;
}
</style>